package com.example.Lezedata.ui.activity.person;

import android.view.View;

import com.example.Lezedata.R;
import com.example.Lezedata.dataManager.GBUserManager;
import com.example.Lezedata.dataManager.LoginManager;
import com.example.Lezedata.net.GBError;
import com.example.Lezedata.net.GBNetRequest;
import com.example.Lezedata.net.ServerResponseObserver;
import com.example.Lezedata.ui.activity.BankCard.BankCardVc;
import com.example.Lezedata.ui.activity.address.AddressListVc;
import com.example.Lezedata.ui.activity.address.Address_addVc;
import com.example.Lezedata.ui.activity.baseClass.GBBaseVc;
import com.example.Lezedata.ui.activity.setting.AccountSecurity;
import com.example.Lezedata.ui.fragment.commonfragment.AlertFragment;
import com.example.Lezedata.util.StatusBarUtil;

import bid.Bid;
import common.Common;

public class PersonVc extends GBBaseVc {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_person;
    }

    @Override
    protected void viewDidLoad() {
        super.viewDidLoad();
        StatusBarUtil.setStatusBarColor(this,R.color.app_color_main);
        StatusBarUtil.setLightStatusBar(this,false,false);
        addAction();
        getUserFinanceAccount();
    }

    void addAction(){
        findViewById(R.id.person_transaction).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpActivity(TransactionsVc.class);
            }
        });

        findViewById(R.id.account_security).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpActivity(AccountSecurity.class);
            }
        });

        findViewById(R.id.person_bank_card).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpActivity(BankCardVc.class);
            }
        });

        findViewById(R.id.person_address).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpActivity(AddressListVc.class);
            }
        });

        findViewById(R.id.person_qa).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        findViewById(R.id.person_about).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        findViewById(R.id.person_out).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginOut();
            }
        });
    }

    void getUserFinanceAccount(){
        GBNetRequest.stubUser().getUserFinanceAccount(Bid.GetUserFinanceAccountRequest.newBuilder().setUserId(GBUserManager.getUserId()).build(),
                ServerResponseObserver.observer(new ServerResponseObserver.requestListener<Bid.GetUserFinanceAccountResponse>() {
                    @Override
                    public void complete(Bid.GetUserFinanceAccountResponse value, GBError error) {
                        if (error == null){

                        }
                    }
                })
        );
    }

    void loginOut(){
        AlertFragment fragment = new AlertFragment();
        fragment.text = "Do you want to log out?";
        fragment.okListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GBNetRequest.stub().logout(Common.EmptyRequest.newBuilder().build(),
                        ServerResponseObserver.observer(new ServerResponseObserver.requestListener<Common.CommonResponse>() {
                    @Override
                    public void complete(Common.CommonResponse value, GBError error) {
                        if (error == null){
                            LoginManager.instance().setLoginStatus(LoginManager.LoginStatus_exit);
                            PersonVc.super.finish();
                        }
                    }
                }));
            }
        };
        fragment.show(getSupportFragmentManager(),"alert");
    }

    @Override
    public int navigationBackgroundColor() {
        return getResources().getColor(R.color.app_color_main);
    }

    @Override
    public int navigationIcon() {
        return R.drawable.app_back_white;
    }
}